<%@page import="java.util.Calendar"%>
<%@page import="com.office.automate.model.employee.EmployeeQualification"%>
<%@page import="com.office.automate.model.employee.Employee"%>
<%@page import="com.office.automate.service.impl.employee.EmployeeQueryServiceImplementer"%>
<%@page import="com.office.automate.service.def.employee.EmployeeQueryService"%>
<%@page import="java.util.List"%>
<%@page import="com.office.automate.exception.framework.FrontierVisibleException"%>
<%@page import="com.office.automate.service.impl.administration.AdministrationServiceImplementer"%>
<%@page import="com.office.automate.service.def.administration.AdministrationService"%>
<%@page import="com.office.automate.configuration.property.DatagridPageConfiguration"%>
<%@page import="com.office.automate.frontier.utility.DataConversionUtility"%>
<%@page import="com.office.automate.configuration.property.ConfigurationProperties"%>
<%@page import="java.util.Properties"%>
<%@page import="com.office.automate.frontier.utility.ExceptionMessagesManagement"%>
<%@page import="com.office.automate.validation.framework.ValidatorObject"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%@ include file="../common/CommonHeaderInfo.jsp"%>
<title>Manage Qualifications</title>
</head>
<body>
	<%@ include file="../common/SiteHeaderSection.jsp" %>
	<%@ include file="../common/EmployeeManagementMenu.jsp"%>
		<%
			if (currentUser == null) {
				return;
			}
			Properties configSeqPropspg = ConfigurationProperties.getProps(); 
			Utility utilpg = new Utility(currentUser.getSecurityLevels());
			if (!utilpg.isFunctionalSecurityAllow(configSeqPropspg.getProperty("MAIN_EMPLOYEE_MANAGEMENT")) ||  
						!utilpg.isFunctionalSecurityAllow(configSeqPropspg.getProperty("ADD_EMPLOYEE_QUALIFICATION")))  {
				response.sendRedirect("/OfficeAutomation/jsp/HomePage.jsp");
			}
			Properties configProps = ConfigurationProperties.getProps();
				    DataConversionUtility dataconversion = new DataConversionUtility();
			String aDataGridPageID = DatagridPageConfiguration.EMPLOYEE_QUALIFICATION_DETAILS;
			String aNextDataRowNumber = (String)request.getAttribute("NextDataRowNumber");
			boolean isValidationErrorExist = false;
			ExceptionMessagesManagement exceptionMessagesManagement  = null;
			EmployeeQualification employeeQualification = (EmployeeQualification) request.getAttribute("Qualification");
			ValidatorObject validationErrors = (ValidatorObject) request.getAttribute("FieldValidationErrors");
			EmployeeQueryService employeeQueryService = new EmployeeQueryServiceImplementer();
			FrontierVisibleException operationalExcaption = (FrontierVisibleException) request.getAttribute("OperationalError");
			if (operationalExcaption != null) {
		%>
		<tr>
			<td>
				<table width="100%" class="operationfaliererror">
					<tr>
						<td>
							<center>
								<font class="operationfaliererrorfont"> <b> Opps.....!!! <%=operationalExcaption.getDetailsErrorMessage() %> </b> <br /> </font>
							</center>
						</td>
					</tr>
		
				</table>
			</td>
		</tr>
		<% } %>
		<tr>
			<td>
				<form action="/OfficeAutomation/QualificationServlet" method="post">
					<center>
						<table>
							<tr>
							<%
						  	Calendar cal=Calendar.getInstance();
						  	int year=cal.get(Calendar.YEAR);
							  if (validationErrors != null) {
									exceptionMessagesManagement = new ExceptionMessagesManagement(validationErrors.getValidationErrorList());
									isValidationErrorExist = true;
							  }
							 %>
								<td>
									<center><font class="formtablecaption"><u>Employee Qualification Registration</u></font></center><br />
									<table class="mainContentStyles">
										<tr>
											<td>Employee</td>
											<td><select name="employeeid">
													<option />
													<%
													List<Employee> list = employeeQueryService.getAllEmployees();
														for (int i=0; i< list.size(); i++) {
															Employee emp = list.get(i);
													%>
														<option value="<%=emp.getEmployeeId() %>" <% if (isValidationErrorExist && employeeQualification.getEmployeeId() == emp.getEmployeeId()) { %> selected="selected" <% } %>><%=emp.getEmployeeId() + "-" + emp.getFirstName() %></option>
													<%
														}
													%>
												</select>
											</td>
										</tr>
										<%
										 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("Employee")) {
										%>
											<tr>
												<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("Employee")  %> </font></td>
											</tr>
										<%
										 }
										%>
										<tr>
											<td>Qualification Type</td>
											<td><select name="qualificationtype">
													<option />
													<%
													int qualificationCount = dataconversion.convertStringToNumber(configProps.getProperty("QUALIFICATION_TYPES_COUNT"));
													for (int i=1; i<=qualificationCount; i++){
														String qualificationCode = (String)configProps.getProperty("QUALIFICATION_"+i);
													%>
														<option value="<%=qualificationCode %>" <% if (isValidationErrorExist && (qualificationCode).equalsIgnoreCase(employeeQualification.getType())) { %> selected="selected" <% } %>><%=(String)configProps.getProperty("QUALIFICATION_"+qualificationCode) %></option>
													<%
													}
													%>
											</select></td>
										</tr>
										<%
										 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("QualificationType")) {
										%>
											<tr>
												<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("QualificationType")  %> </font></td>
											</tr>
										<%
										 }
										%>
										<tr>
											<td>Description</td>
											<td><input type="text" name="description" <% if (isValidationErrorExist) { %> value="<%=employeeQualification.getDescription() %>" <% } %> ></td>
										</tr>
									    <%
										 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("Description")) {
										%>
											<tr>
												<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("Description")  %> </font></td>
											</tr>
										<%
										 }
										%>
										<tr>
											<td>Start Date</td>
											<td>
											  <select name="startdate">
											  	<%
											  		for (int i=1; i<=31; i++) {
												%>
													<option value="<%=i %>" <% if (isValidationErrorExist && i == employeeQualification.getStartDate().getDate()) { %> selected="selected" <% } %>><%=i %></option>
												<%
											  		}
											  	%>
											 </select>
													<select name="startmonth">
													<%
			
														for (int i=0; i<12; i++) {
													%>
															<option value="<%=i+1 %>" <% if (isValidationErrorExist && i == employeeQualification.getStartDate().getMonth()) { %> selected="selected" <% } %>><%=dataconversion.getMonthDescription(i) %></option>
													<%
														}
													%>
				  							  </select>
											  <select name="startyear">
											  	<%
											  		for(int i=1930; i <= year; i++) {
											  	%>
													     <option value="<%=i %>" <% if (isValidationErrorExist && i == employeeQualification.getStartDate().getYear()) { %> selected="selected" <% } %>><%=i %></option>
												<%
											  		}
											  	%>
											  </select>
											</td>
										</tr>
										<%
										 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("StartDate")) {
										%>
											<tr>
												<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("StartDate")  %> </font></td>
											</tr>
										<%
										 }
										%>
										<tr>
											<td>End Date</td>
											<td>
											  <select name="enddate">
											  	<%
											  		for (int i=1; i<=31; i++) {
												%>
													<option value="<%=i %>" <% if (isValidationErrorExist && i == employeeQualification.getEndDate().getDate()) { %> selected="selected" <% } %>><%=i %></option>
												<%
											  		}
											  	%>
											 </select>
													<select name="endmonth">
													<%
			
														for (int i=0; i<12; i++) {
													%>
															<option value="<%=i+1 %>" <% if (isValidationErrorExist && i == employeeQualification.getEndDate().getMonth()) { %> selected="selected" <% } %>><%=dataconversion.getMonthDescription(i) %></option>
													<%
														}
													%>
				  							  </select>
											  <select name="endyear">
											  	<%
											  		for(int i=1930; i <= year; i++) {
											  	%>
													     <option value="<%=i %>" <% if (isValidationErrorExist && i == employeeQualification.getEndDate().getYear()) { %> selected="selected" <% } %>><%=i %></option>
												<%
											  		}
											  	%>
											  </select>
											</td>
										</tr>
										<%
										 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("EndDate")) {
										%>
											<tr>
												<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("EndDate")  %> </font></td>
											</tr>
										<%
										 }
										%>	
									</table>
								</td>
							</tr>
							<tr>
								<td colspan="2"><div class="formButtonPanel"><input type="reset" class="buttonstyle"> <input class="buttonstyle" type="submit" name="submit" value="Submit" /></div></td>
							</tr>
						</table>
					</center>
				 </form>
			</td>
		</tr>
		<tr>
			<td height="20px">
			
			</td>
		</tr>
		<tr>
			<td>
				<center>
				        <jsp:include page="../frameworks/DataGridComponent.jsp">
			            	<jsp:param name="aDataGridPageID" value="<%=aDataGridPageID %>" />
			            	<jsp:param name="aNextRowNumber" value="<%=aNextDataRowNumber %>" />
			            	<jsp:param name="aButtonDeleteCaption" value="Delete" />
			            	<jsp:param name="aButtonsNextPrevious" value="true" />
			        	</jsp:include>
				</center>
			</td>
		</tr>
<%@ include file="../common/SiteFotterSection.jsp" %>
</body>
</html>